package com.magenta.maxoptra.dto;

import org.apache.commons.lang.StringUtils;

import java.io.Serializable;

/**
 * @author Zaur Muhametgaleev
 * @version 11/23/11 3:27 PM
 * @since Maxoptra 3 (Geo services - Openlayers routing)
 */
public class GeoLocationRecord implements Serializable {

    private static final long serialVersionUID = 203591557268729L;

    private double distanceToNextPoint;

    public Long id;

    public String name;

    public Double latitude;

    public Double longitude;

    public double getDistanceToNextPoint() {
        return distanceToNextPoint;
    }

    public void setDistanceToNextPoint(double distanceToNextPoint) {
        this.distanceToNextPoint = distanceToNextPoint;
    }

    public GeoLocationRecord(Double longitude, Double latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }

    public GeoLocationRecord(Double longitude, Double latitude, double distanceToNextPoint) {
        this.longitude = longitude;
        this.latitude = latitude;
        this.distanceToNextPoint = distanceToNextPoint;
    }

    public GeoLocationRecord(String longitude, String latitude) {
        if(StringUtils.isEmpty(longitude) || StringUtils.isEmpty(latitude)){
            throw new IllegalStateException("Incorrect coordinates. Longitude: " +
                    longitude + ", Latitude: " + latitude);
        }

        this.longitude = Double.parseDouble(longitude);
        this.latitude = Double.parseDouble(latitude);
    }


    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        GeoLocationRecord record = (GeoLocationRecord) o;

        if (id != null ? !id.equals(record.id) : record.id != null) return false;
        if (name != null ? !name.equals(record.name) : record.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

    public Long getId () {
        return id;
    }

    public void setId ( Long id ) {
        this.id = id;
    }

    public String getName () {
        return name;
    }

    public void setName ( String name ) {
        this.name = name;
    }

    protected void copy(GeoLocationRecord record) {
        this.id = record.getId();
        this.name = record.getName();
        this.latitude = record.latitude;
        this.longitude = record.longitude;
    }

}
